<?php

class bookApp extends Control {

	public function index(){
		
		$book_id = isset($_GET['bid'])? intval($_GET['bid']) : 0;
		
		if (!$book_id) {
			$this->show_message("图书信息不存在");
			exit();
		}
		
		$book_mod = &get_model("book");
		$article_mod = &get_model("article");
		
		
		$book_info = $book_mod->get_book_info($book_id);
		$article_info = $article_mod->get_book_article($book_id);
		//dump($book_info);
		switch ($book_info['structure_id']) {
			case 1:
				break;
			case 2:
				$chapter_mod = &get_model("chapter");
				$chapter_info = $chapter_mod->get_book_chapter($book_id);
				
				$article_group_by_chapter = array();
				foreach ($article_info as $a) {
					$article_group_by_chapter[$a['chapter_id']][] = $a;
				}
				//dump($chapter_info);
				//dump($article_group_by_chapter);
				$this->assign('chapter_info', $chapter_info);
				$this->assign('article_group_by_chapter', $article_group_by_chapter);
			break;
		}
		
		$breadcrumb = array(
					
		);
		
		$this->assign('breadcrumb', $breadcrumb);
		$this->assign('book_info', $book_info);
		$this->assign('article_info', $article_info);
		$this->display();
	}
	
}
